<?php

namespace app\common\model;

use think\Model;

class WaterModel extends Model
{
    protected $name = 'water';

    /**写入喝水提醒
     * @param string $robotId
     * @param string $wxId
     * @param int $type
     * @param string $content
     * @return int|string
     */
    public function insertWaterData(string $robotId,string $wxId,$type = 1,$content = ''){
        return $this->insert([
            'wx_id'=>$wxId,
            'robot_id'=>$robotId,
            'type'=>$type,
            'content'=>$content
        ]);
    }

    /**查询喝水提醒数据
     * @param array $where
     * @return array
     */
    public function getWaterData(array $where): array
    {
        return $this->where(['robot_id'=>$where['robot_wxid'],'wx_id'=>$where['final_from_wxid']])->findOrEmpty()->toArray();
    }

    public function setWaterData(array $where,$data = ['type'=>1])
    {
        $this->where(['robot_id'=>$where['robot_wxid'],'wx_id'=>$where['final_from_wxid']])->update($data);
    }

}